﻿using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.CourseTrain;
using NP.BPMReportPlatform.CourseTrain.Dtos;
using NP.BPMReportPlatform.DBHelper;
using NP.BPMReportPlatform.ElectronicSign;
using NP.BPMReportPlatform.RecurringJobs;
using NP.BPMReportPlatform.Samples;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NP.BPMReportPlatform
{
    /// <summary>
    /// 第三方请求
    /// </summary>
    [Route("api/thridrequest")]
    public class ThirdRequestController : ControllerBase
    {
        private readonly IESService _esService;
        private readonly IRiskService _riskService;
        private readonly ICourseTrainTaskService _courseTrainTaskService;

        public ThirdRequestController(IESService esService, IRiskService riskService, ICourseTrainTaskService courseTrainTaskService)
        {
            _esService = esService;
            _riskService = riskService;
            _courseTrainTaskService = courseTrainTaskService;
        }

        /// <summary>
        /// 电子签回调接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("esign/update")]
        [IgnoreApiResult(Order = 100)]
        public async Task<object> EsignUpdate([FromBody] ESDto.ESFlowRequest request)
        {
            ESDto.ESCommonResponseForOne result = await _esService.UpdateSignStatus(request);
            return new
            {
                errCode = result.ErrCode,
                errShow = result.ErrShow,
                msg = result.Msg,
            };
        }

        /// <summary>
        /// Risk回调接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("risk/update")]
        [IgnoreApiResult(Order = 100)]
        public async Task<RiskDto.UpdateResponseData> RiskUpdate([FromBody] RiskDto.UpdateRequestData request)
        {
            return await _riskService.UpdateStatus(request);
        }

        /// <summary>
        /// 报销获取培训人员信息接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("reimbursement/get-train-user")]
        [IgnoreApiResult(Order = 100)]
        public async Task<TrainingMasterDataDto.ResponseDto> GetTrainUser([FromBody] TrainingMasterDataDto.RequestDto request)
        {
            return await _courseTrainTaskService.GetReimbursementTrainUser(request);
        }

        /// <summary>
        /// RISK获取培训人员信息接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("reimbursement/get-train-task-info")]
        [IgnoreApiResult(Order = 100)]
        public TrainTaskInfoDto GetTrainUser([FromQuery]string id)
        {
            return _courseTrainTaskService.GetTrainTaskInfo(id);
        }
    }
}
